package edu.pku.sei.gefcommon.descriptor.descriptors;

import org.eclipse.draw2d.geometry.Point;
import org.eclipse.ui.views.properties.TextPropertyDescriptor;

public class PointPropertyDescriptor extends TextPropertyDescriptor {
	public PointPropertyDescriptor(Object id, String name,String catalog) {
		super(id, name);
		this.setCategory(catalog);
		this.setValidator(GeometryValidator.pointValidator);
	}
	static public String fromModel(Point value){
		if(value==null) return "0,0";
		return value.x+","+value.y;
	}
	static public Point toModel(String value){
		String[] pt = value.split(",");
		Point p = new Point();
		p.x = Integer.parseInt(pt[0]);
		p.y = Integer.parseInt(pt[1]);
		return p;
	}
}
